<?php

namespace mpend\components;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * WechatJsSdkRegisterTrait
 * @author emhome
 */
trait WechatJsSdkRegisterTrait {

    private $_jsapi = [];

    /**
     * 获取当前站点登录用户的openid
     *  [
     *      'jsApiList' => [
     *          'onMenuShareTimeline',
     *          'onMenuShareAppMessage',
     *      ]
     *  ]
     */
    public function getJsApiConfig() {
        if (!YII_ENV_PROD) {
            return false;
        }
        return Yii::$app->wechat->jsApiConfig();
    }

    /**
     * 获取当前站点登录用户的openid
     */
    public function setJsApi(array $data) {
        if (is_array($data) && !empty($data)) {
            $this->_jsapi = ArrayHelper::merge($this->_jsapi, $data);
        }
    }

    /**
     * 获取当前站点登录用户的openid
     */
    public function getJsApi() {
        return $this->_jsapi;
    }

}
